﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmTinhThanh : DevExpress.XtraEditors.XtraForm
    {
        public frmTinhThanh()
        {
            InitializeComponent();
        }

        public int TinhThanhId
        {
            get;
            set;
        }

        private void frmTinhThanh_Load(object sender, EventArgs e)
        {
            tblTinhThanhTableAdapter.Fill(dsDiaChi.tblTinhThanh);

            if (this.TinhThanhId != 0)
            {
                tblTinhThanhBindingSource.MoveFirst();
                for (int i = 0; i < tblTinhThanhBindingSource.Count; i++)
                {
                    QLTV.Database.dsDiaChi.tblTinhThanhRow tinhthanh = (QLTV.Database.dsDiaChi.tblTinhThanhRow)((DataRowView)tblTinhThanhBindingSource.Current).Row;
                    if (tinhthanh.TinhThanhID == this.TinhThanhId)
                    {
                        break;
                    }
                    else
                    {
                        tblTinhThanhBindingSource.MoveNext();
                    }
                }
            }
            else
            {
                tblTinhThanhBindingSource.AddNew();
            }


        }
        void updateTinhThanh()
        {
            if (dxValidationProvider1.Validate())
            {
                tblTinhThanhBindingSource.EndEdit();
                tblTinhThanhTableAdapter.Update(dsDiaChi.tblTinhThanh);

            }
        }

        private void cmdSaveInsert_Click(object sender, EventArgs e)
        {
            updateTinhThanh();
            tblTinhThanhBindingSource.AddNew();
        }

        private void cmdLuuVaDong_Click(object sender, EventArgs e)
        {
            updateTinhThanh();
            this.Close();
        }

        private void cmdDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}